package gentle.controller;

import com.baomidou.mybatisplus.plugins.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import gentle.service.ICustomerService;
import gentle.entity.*;
import gentle.factory.*;
import java.util.List;
import gentle.base.BaseController;

/**
 * @author py
 * @Date 2019年4月19日23:15:54
 */
@Controller
@RequestMapping("/customer")
public class CustomerController  extends BaseController {

    @Autowired
    ICustomerService customerService;

    /**
     * 患者信息列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public Object testrInfoList(SearchCustomerInfo info) {
        if (info.getAbbreviation() == null || info.getAbbreviation() == "" || info.getAbbreviation() == "null") {
            return null;
        } else {
            Page<CustomerInfo> page = new PageFactory<CustomerInfo>().defaultPage();
            try {
                info.setStartIndex(page.getSize() * (page.getCurrent() - 1));
                info.setLimitIndex(page.getSize());
                page.setCurrent(0);
                List<CustomerInfo> list = customerService.selectPageListByQueryGetMap(page, info);
                if (list.size() == 0) {
                    info.setStartIndex(0);
                    list = customerService.selectPageListByQueryGetMap(page, info);
                }
                page.setTotal(customerService.getQueryPagesCount(page, info));
                page.setRecords(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return super.packForBT(page);
        }
    }

}